package com.crm.util;

import java.sql.*;

/**
 * @version : 1.0
 * @auther : hjx
 * @Date : 2021/6/11
 * @Description : 实训
 */
public class jdbcUtils {

    public static Connection getCon() {
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/crm?useUnicode=true&useSSL=false&characterEncoding=utf-8&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "19834534612";

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(url,username,password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void close(Connection connection,Statement statement,ResultSet resultSet) {

        try {
            if (connection != null) {
                connection.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
